<template>
  <div>
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px">
      <el-form-item label="用户编号" prop="uId">
        <el-input v-model="ruleForm.uId" placeholder="请输入编号信息" :disabled="true" style="width: 260px" ></el-input>
      </el-form-item>
      <el-form-item label="用户姓名" prop="username">
        <el-input v-model="ruleForm.username" placeholder="请输入用户名称" style="width: 260px"></el-input>
      </el-form-item>
      <el-form-item label="用户密码" prop="password">
        <el-input v-model="ruleForm.password" placeholder="请输入用户密码" style="width: 260px"></el-input>
       <!-- <el-button title="重置密码" @click="resetPass('ruleForm.password')" type="primary" icon="el-icon-refresh" size="small" circle></el-button> -->
      </el-form-item>
      <el-form-item label="用户类型" prop="uType">
       <el-select v-model="ruleForm.uType" placeholder="请选择" style="width: 260px">
         <!-- <el-option v-for="entry in roles" :label="entry.rName" :value="entry.rId" :key="entry.rId"></el-option> -->
         <el-option label="超级管理员" value="1"></el-option>
         <el-option label="客服" value="2"></el-option>
         <el-option label="任务调度" value="3"></el-option>
         <el-option label="技术工程师" value="4"></el-option>
         <el-option label="库管" value="5"></el-option>
         <el-option label="运营监督" value="6"></el-option>
       </el-select>
      </el-form-item>

     <el-form-item style="margin-top: 20px">
        <el-button type="primary" @click="editUser">保存修改</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    
  </div>
</template>
<script>
import {editUser as editUser} from '../../../api/user';
import {getOne as getOne} from '../../../api/user';
import { getRoleforUser as getRoleforUser} from "../../../api/user";
// import { getMap } from "../../utils/dataStorage";

export default {
  inject:['reload'],
  props:["uId"],
  data() {
    return {
      roles:{
        rId:"",
        rName:"",
      },
      ruleForm: {
        uId: "",
        username: "",
        password: "",
        uType: "",
        //password: "123456",
        isEffectice:"1"
        //createTime: ""
      },
      rules: {

        username: [
          { required: true, message: "请输入客户姓名", trigger: "blur" },
          { min: 1, max: 10, message: "长度在 1-10个字符", trigger: "blur" }
        ],
        
        uType: [
          { required: true, message: "请选择用户类型", trigger: "blur" }
        ],
        
        password: [
          { required: true, message: "请输入密码", trigger: "blur" }
        ],
      },
       buttonText:"修改"
      //buttonText:"创建"
    }
  },
  created(){
      //显示密码123456
       // this.getRoleforUser();
        //  this.get("emp/getDeptJob",(data)=>{
        //     this.jobs=data.jobs;
        //     this.depts=data.depts;
        // });

        if(this.uId){
                let param = new URLSearchParams();
                param.append('uId', this.uId);
                this.getOne(param);
               
            }
        //this.getUserInfo();
           
    },
  components: {},
  methods: {
    // getRoleforUser(){
    //   let that = this;
    //      getRoleforUser()
    //     .then(r => {
    //       //this.roles = r;
    //       console.log(r);
    //       this.form.cName = r.service.cName;
    //     })
    //     .catch(_ => {
    //       console.log(_);
    //     });
    // },
    editUser() {
          let param = new URLSearchParams();
          param.append('uId',this.uId);
          param.append("username", this.ruleForm.username);
          param.append("password", this.ruleForm.password);
          param.append("uType", this.ruleForm.uType);
          param.append("isEffectice",this.ruleForm.isEffectice);
          if(this.ruleForm.password === ""){
            alert("请输入密码！");
          }else if(this.ruleForm.uType === ""){
            alert("请输入用户类型！");
          }else{
              editUser(param).then(r=>{
                setTimeout(() => {
                  this.$notify({
                    title:"修改用户成功",
                    type:"success"
                  });
                },1000);
                this.$layer.closeAll(); //疯狂模式，关闭所有层
                location.reload(true) //关闭刷新
              }).catch(_=>{
                this.$notify({
                    title:"修改用户失败",
                    type:"false"
                  });
                  console.log("修改用户户信息失败！");
              });
         }
    },
    resetForm(formName){
        this.$refs[formName].resetFields();
    },
    //重置密码
    resetPass(){

    },
    getOne(param) {
      let that = this;
      // 执行方法
      getOne(param).then(r=>{
        console.log("id",this.uId);
        console.log(r);
        that.ruleForm = r.users;
        that.ruleForm.uType = r.users.uType + "";
      

        that.roles = r.roles;

      }).catch(_=>{
        console.log("获取用户信息失败！");
      })
    }
  }
};
</script>